package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xwl
 * Date: 2023-06-14
 * Time: 7:39
 */
public class ThreadDemo5 {
    // lambda变量捕获规则，因此写成成员变量
    public static boolean flag = false;
    public static void main(String[] args) {
        Thread t = new Thread( () -> {
           while (!flag) {
               System.out.println("hello t");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        }, "我的线程1");
         //
        t.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //
        flag = true;

    }
}
